package com.subway.babynote.syncservice;

import java.util.List;

import com.subway.babynote.NotedbHelper;
import com.subway.babynote.db.TableInfoList;
import com.subway.babynote.syncdata.ClientDataRecord;
import com.subway.babynote.syncdata.tableName;
import com.subway.babynote.syncdata.ClientDataRecord.uxRecord;

import android.app.Activity;
import android.content.Context;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.database.SQLException;
import android.os.IBinder;
import android.util.Log;

public abstract class syncapi {
	public static class operation_code {
		public static final int addFeedback = 1;
		public static final int changeUserInfo = 2;
		public static final int addFeedRecord = 3;
		public static final int getLastAverage = 4;
		public static final int getFeeds = 5;
		public static final int getFoodprop = 6;
		public static final int getFoods = 7;

		public static final int addh = 8;
		public static final int addw = 17;

		public static final int getTip = 9;
		public static final int regVisitor = 10;
		public static final int regUser = 11;
		public static final int loginUser = 12;
		public static final int getts = 13;
		public static final int getcontact = 14;
		public static final int getloadinfo = 15;
		public static final int getts2 = 16;

		public static final int syncweibo = 18;
		public static final int getweibo = 19;
		public static final int logout = 20;
		public static final int unbindweibo = 21;

		public static final int get_h_default = 22;
		public static final int get_h_ux = 23;
		public static final int get_w_default = 24;
		public static final int get_w_ux = 25;
		public static final int get_food_default = 26;
		public static final int get_food_ux = 27;

		public static final int geth = 28;
		public static final int getw = 29;

	}

	public static class operation_type {
		public static final o_type addFeedback = new o_type(
				operation_code.addFeedback, "addFeedback",
				tableName.t_feedbacks, true);
		public static final o_type changeUserInfo = new o_type(
				operation_code.changeUserInfo, "ChangeUserInfo",
				tableName.t_users, true);
		public static final o_type addFeedRecord = new o_type(
				operation_code.addFeedRecord, "FeedSync", tableName.t_feeds,
				true);
		public static final o_type getLastAverage = new o_type(
				operation_code.getLastAverage, "getavg", tableName.t_local_avg,
				false);
		public static final o_type getFeeds = new o_type(
				operation_code.getFeeds, "getfeeds", tableName.t_feeds, false);
		public static final o_type getFoodprop = new o_type(
				operation_code.getFoodprop, "getfoodprop",
				tableName.t_food_prop, false);
		public static final o_type getFoods = new o_type(
				operation_code.getFoods, "getfoodtable", tableName.t_foods,
				false);

		public static final o_type getTip = new o_type(operation_code.getTip,
				"gettip", tableName.t_tips, false);
		public static final o_type regVisitor = new o_type(
				operation_code.regVisitor, "RegVisitor", tableName.t_users,
				true);
		public static final o_type regUser = new o_type(operation_code.regUser,
				"RegUser", tableName.t_users, true);
		public static final o_type loginUser = new o_type(
				operation_code.loginUser, "Login", tableName.t_users, true);
		public static final o_type getts = new o_type(operation_code.getts,
				"getts", tableName.t_ts, false);

		public static final o_type getcontact = new o_type(
				operation_code.getcontact, "getcontact",
				tableName.t_ourcontact, false);
		public static final o_type getloadinfo = new o_type(
				operation_code.getloadinfo, "getloadinfo",
				tableName.t_loadinfo, false);

		public static final o_type syncweibo = new o_type(
				operation_code.syncweibo, "syncweibo", tableName.t_weibo, false);
		public static final o_type getweibo = new o_type(
				operation_code.getweibo, "getweibo", tableName.t_weibo, false);
		public static final o_type logout = new o_type(operation_code.logout,
				"logout", tableName.t_users, false);
		public static final o_type unbindweibo = new o_type(
				operation_code.unbindweibo, "unbindweibo", tableName.t_weibo,
				false);

		public static final o_type addh = new o_type(operation_code.addh,
				"addh", tableName.t_huser, true);
		public static final o_type addw = new o_type(operation_code.addw,
				"addw", tableName.t_wuser, true);
		public static final o_type get_h_default = new o_type(
				operation_code.get_h_default, "get_h_default",
				tableName.t_h_default, false);
		public static final o_type get_h_ux = new o_type(
				operation_code.get_h_ux, "get_h_ux", tableName.t_h_ux, false);
		public static final o_type get_w_default = new o_type(
				operation_code.get_w_default, "get_w_default",
				tableName.t_w_default, false);
		public static final o_type get_w_ux = new o_type(
				operation_code.get_w_ux, "get_w_ux", tableName.t_w_ux, false);
		public static final o_type get_food_default = new o_type(
				operation_code.get_food_default, "get_food_default",
				tableName.t_food_default, false);
		public static final o_type get_food_ux = new o_type(
				operation_code.get_food_ux, "get_food_ux", tableName.t_food_ux,
				false);
		public static final o_type geth = new o_type(operation_code.geth,
				"geth", tableName.t_avg_height, false);
		public static final o_type getw = new o_type(operation_code.getw,
				"getw", tableName.t_avg_weight, false);

		public static final int operation_length = 29;
	}

	public static class inform_key {
		public static final String code = "c";
		public static final String ts = "t";
	}

	public static final int inform_code = 0x00001234;

	public abstract int informSync(int icode, int ts);

	public abstract int Init(Context context);

	public abstract void Destroy();

	// need fill:email, password, gender, birth
	public abstract int RegUser(ClientDataRecord.usersRecord ur);

	public abstract int LoginUser(String username, String passwd);

	public abstract int Logout();

	public abstract int syncWeibo(String username, String passwd);

	public abstract int UnbindWeibo();

	private static final syncapi psyncapi = new syncapi_impl();

	public static syncapi getSyncImpl() {
		// ????zfp
		return psyncapi;
	}

	// function needs db info from UI
	public abstract int AddFeed(ClientDataRecord.feedRecord fr) ;

	public abstract int AddVisitor(int birth, boolean gender) ;
	
	public abstract int AddUser(int birth, boolean gender,String email, String password ) ;

	// not sure if this table split ot Height and Weight Table?
	public abstract int AddHUser(float height);
	public abstract int AddWUser(float weight);

	public abstract int AddFeedback(String content);
	//
	public abstract int updateUserInfo(int birth, boolean gender);

	// return the cur of Food by a specified category

	public abstract List<ClientDataRecord.foodsRecord> getFoodybyCategory(String category) ;
	
	public abstract List<ClientDataRecord.feedRecord>  getFeedbyCategory(String category);

	public abstract List<ClientDataRecord.foodsRecord> getFoodbyProp(int prop_id) ;

	// get our contact info from db
	public abstract List<ClientDataRecord.contactRecord> getOurContact();

	// get the records from the local_avg
	public abstract List<ClientDataRecord.last_avgRecord> getAverage() ;

	public abstract int getFoodPropid(String food_prop);

	public abstract ClientDataRecord.weiboRecord getWeibo() ;

	// get record from the tips table
	public abstract List<ClientDataRecord.tipRecord> getTips() ;

	// get record from the localinfo table
	public abstract ClientDataRecord.loadinfoRecord getLoadInfo() ;

	// get user record from the User table
	public abstract ClientDataRecord.usersRecord getUser() ;

	public abstract boolean getUserGender() ;

	public abstract int getUserAge() ;

	// get User id from the User table
	public abstract int getUserid();
	public abstract int getVisitorid();

	// get record from food by foodname
	public abstract ClientDataRecord.foodsRecord getFood(String foodname) ;

	// get record by foodid
	public abstract ClientDataRecord.foodsRecord getFood (int food_id) ;

	// get min ,mid ,max weight info
	public abstract ClientDataRecord.hwAvgRecord getWeight(int age, boolean gender) ;

	// get min mid max weight info
	public abstract ClientDataRecord.hwAvgRecord getHeight(int age, boolean gender) ;
	// get Sum Record of feed
	public abstract List<ClientDataRecord.clientFeedRecord> getSumFeeds(int date);
	// get Feed records
	public abstract List<ClientDataRecord.clientFeedRecord> getFeeds(int date);
	
	public abstract uxRecord getWeightSuggestion();
	public abstract uxRecord getHeightSuggestion();
	public abstract uxRecord getFoodSuggestion(int food_id);
}